home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / clients / xcalc / actions.c next >
Encoding:
C/C++ Source or Header  |  1994-08-12  |  10.2 KB  |  550 lines

  1. /*
  2.  * $XConsortium: actions.c,v 1.8 91/03/22 18:27:15 converse Exp $
  3.  *
  4.  * actions.c - externally available procedures for xcalc
  5.  *
  6.  * Copyright 1989 by the Massachusetts Institute of Technology
  7.  *
  8.  * Permission to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted, provided 
  10.  * that the above copyright notice appear in all copies and that both that 
  11.  * copyright notice and this permission notice appear in supporting 
  12.  * documentation, and that the name of M.I.T. not be used in advertising
  13.  * or publicity pertaining to distribution of the software without specific, 
  14.  * written prior permission. M.I.T. makes no representations about the 
  15.  * suitability of this software for any purpose.  It is provided "as is"
  16.  * without express or implied warranty.
  17.  *
  18.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  19.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  20.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  21.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  22.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  23.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  *
  25.  * Author:  Donna Converse, MIT X Consortium
  26.  */
  27.  
  28. #ifdef MSDOS
  29. #include "X11/Intrinsc.h"      /* QDK 05/17/1994  3:17pm. */
  30. #else
  31. #include "X11/Intrinsic.h"
  32. #endif
  33. #include <setjmp.h>
  34. #include "xcalc.h"
  35. extern int rpn;
  36. extern Atom wm_delete_window;
  37. extern int pre_op();
  38. extern void post_op(), Quit(), ringbell(), do_select();
  39.  
  40. #ifndef IEEE
  41. extern    jmp_buf env;
  42. extern void fail_op();
  43. #define XCALC_PRE_OP(keynum) { if (pre_op(keynum)) return; \
  44.                if (setjmp (env)) {fail_op(); return;}}
  45. #else
  46. #define XCALC_PRE_OP(keynum) if (pre_op(keynum)) return;
  47. #endif
  48.  
  49. /*ARGSUSED*/
  50. void add(w, e, vector, count)
  51.     Widget    w;
  52.     XEvent    *e;
  53.     String    *vector;
  54.     Cardinal    *count;
  55. {
  56.     XCALC_PRE_OP(kADD);
  57.     rpn ? twof(kADD) : twoop(kADD);
  58.     post_op();
  59. }
  60.  
  61. /*ARGSUSED*/
  62. void back(w, e, vector, count)
  63.     Widget    w;
  64.     XEvent    *e;
  65.     String    *vector;
  66.     Cardinal    *count;
  67. {
  68.     XCALC_PRE_OP(kBKSP);
  69.     bkspf();
  70.     post_op();
  71. }
  72.  
  73. /*ARGSUSED*/
  74. void bell(w, e, vector, count)
  75.     Widget    w;
  76.     XEvent    *e;
  77.     String    *vector;
  78.     Cardinal    *count;
  79. {
  80.     ringbell();
  81. }
  82.  
  83. /*ARGSUSED*/
  84. void clearit(w, e, vector, count)
  85.     Widget    w;
  86.     XEvent    *e;
  87.     String    *vector;
  88.     Cardinal    *count;
  89. {
  90.     XCALC_PRE_OP(kCLR);
  91.     clearf();
  92.     post_op();
  93. }
  94.    
  95. /*ARGSUSED*/
  96. void cosine(w, e, vector, count)
  97.     Widget    w;
  98.     XEvent    *e;
  99.     String    *vector;
  100.     Cardinal    *count;
  101. {
  102.     XCALC_PRE_OP(kCOS);
  103.     oneop(kCOS);
  104.     post_op();
  105. }
  106.  
  107. /*ARGSUSED*/
  108. #ifndef __GNUC__
  109. void decimal(w, e, vector, count)
  110. #else
  111. void xcalc_decimal(w, e, vector, count)
  112. #endif
  113.     Widget    w;
  114.     XEvent    *e;
  115.     String    *vector;
  116.     Cardinal    *count;
  117. {
  118.     XCALC_PRE_OP(kDEC);
  119.     decf();
  120.     post_op();
  121. }
  122.  
  123. /*ARGSUSED*/
  124. void degree(w, e, vector, count)
  125.     Widget    w;
  126.     XEvent    *e;
  127.     String    *vector;
  128.     Cardinal    *count;
  129. {
  130.     XCALC_PRE_OP(kDRG);
  131.     drgf();
  132.     post_op();
  133. }
  134.  
  135. /*ARGSUSED*/
  136. void digit(w, e, vector, count)
  137.     Widget    w;
  138.     XEvent    *e;
  139.     String    *vector;
  140.     Cardinal    *count;
  141. {
  142.     switch (vector[0][0])
  143.     {
  144.       case '1':    XCALC_PRE_OP(kONE); numeric(kONE); break;
  145.       case '2': XCALC_PRE_OP(kTWO); numeric(kTWO); break;
  146.       case '3': XCALC_PRE_OP(kTHREE); numeric(kTHREE); break;
  147.       case '4': XCALC_PRE_OP(kFOUR); numeric(kFOUR); break;
  148.       case '5': XCALC_PRE_OP(kFIVE); numeric(kFIVE); break;
  149.       case '6': XCALC_PRE_OP(kSIX); numeric(kSIX); break;
  150.       case '7': XCALC_PRE_OP(kSEVEN); numeric(kSEVEN); break;
  151.       case '8': XCALC_PRE_OP(kEIGHT); numeric(kEIGHT); break;
  152.       case '9': XCALC_PRE_OP(kNINE); numeric(kNINE); break;
  153.       case '0': XCALC_PRE_OP(kZERO); numeric(kZERO); break;
  154.     }
  155.     post_op();
  156. }
  157.  
  158. /*ARGSUSED*/
  159. void divide(w, e, vector, count)
  160.     Widget    w;
  161.     XEvent    *e;
  162.     String    *vector;
  163.     Cardinal    *count;
  164. {
  165.     XCALC_PRE_OP(kDIV);
  166.     rpn  ? twof(kDIV) : twoop(kDIV);
  167.     post_op();
  168. }
  169.  
  170. /*ARGSUSED*/
  171. void e(w, ev, vector, count)
  172.     Widget    w;
  173.     XEvent    *ev;
  174.     String    *vector;
  175.     Cardinal    *count;
  176. {
  177.     XCALC_PRE_OP(kE);
  178.     oneop(kE);
  179.     post_op();
  180. }
  181.  
  182. /*ARGSUSED*/
  183. void enter(w, e, vector, count)
  184.     Widget    w;
  185.     XEvent    *e;
  186.     String    *vector;
  187.     Cardinal    *count;
  188. {
  189.     XCALC_PRE_OP(kENTR);
  190.     entrf();
  191.     post_op();
  192. }
  193.  
  194. /*ARGSUSED*/
  195. void epower(w, e, vector, count)
  196.     Widget    w;
  197.     XEvent    *e;
  198.     String    *vector;
  199.     Cardinal    *count;
  200. {
  201.     XCALC_PRE_OP(kEXP);
  202.     oneop(kEXP);
  203.     post_op();
  204. }
  205.  
  206. /*ARGSUSED*/
  207. void equal(w, e, vector, count)
  208.     Widget    w;
  209.     XEvent    *e;
  210.     String    *vector;
  211.     Cardinal    *count;
  212. {
  213.     XCALC_PRE_OP(kEQU);
  214.     equf();
  215.     post_op();
  216. }
  217.  
  218. /*ARGSUSED*/
  219. void exchange(w, e, vector, count)
  220.     Widget    w;
  221.     XEvent    *e;
  222.     String    *vector;
  223.     Cardinal    *count;
  224. {
  225.     XCALC_PRE_OP(kEXC);
  226.     oneop(kEXC);
  227.     post_op();
  228. }
  229.    
  230. /*ARGSUSED*/
  231. void factorial(w, e, vector, count)
  232.     Widget    w;
  233.     XEvent    *e;
  234.     String    *vector;
  235.     Cardinal    *count;
  236. {
  237.     XCALC_PRE_OP(kFACT);
  238.     oneop(kFACT);
  239.     post_op();
  240. }
  241.  
  242. /*ARGSUSED*/
  243. void inverse(w, e, vector, count)
  244.     Widget    w;
  245.     XEvent    *e;
  246.     String    *vector;
  247.     Cardinal    *count;
  248. {
  249.     XCALC_PRE_OP(kINV);
  250.     invf();
  251.     post_op();
  252. }
  253.    
  254. /*ARGSUSED*/
  255. void leftParen(w, e, vector, count)
  256.     Widget    w;
  257.     XEvent    *e;
  258.     String    *vector;
  259.     Cardinal    *count;
  260. {
  261.     XCALC_PRE_OP(kLPAR);
  262.     lparf();
  263.     post_op();
  264. }
  265.    
  266. /*ARGSUSED*/
  267. void logarithm(w, e, vector, count)
  268.     Widget    w;
  269.     XEvent    *e;
  270.     String    *vector;
  271.     Cardinal    *count;
  272. {
  273.     XCALC_PRE_OP(kLOG);
  274.     oneop(kLOG);
  275.     post_op();
  276. }
  277.  
  278. /*ARGSUSED*/
  279. void multiply(w, e, vector, count)
  280.     Widget    w;
  281.     XEvent    *e;
  282.     String    *vector;
  283.     Cardinal    *count;
  284. {
  285.     XCALC_PRE_OP(kMUL);
  286.     rpn ? twof(kMUL) : twoop(kMUL);
  287.     post_op();
  288. }
  289.    
  290. /*ARGSUSED*/
  291. void naturalLog(w, e, vector, count)
  292.     Widget    w;
  293.     XEvent    *e;
  294.     String    *vector;
  295.     Cardinal    *count;
  296. {
  297.     XCALC_PRE_OP(kLN);
  298.     oneop(kLN);
  299.     post_op();
  300. }
  301.    
  302. /*ARGSUSED*/
  303. void negate(w, e, vector, count)
  304.     Widget    w;
  305.     XEvent    *e;
  306.     String    *vector;
  307.     Cardinal    *count;
  308. {
  309.     XCALC_PRE_OP(kNEG);
  310.     negf();
  311.     post_op();
  312. }
  313.  
  314. /*ARGSUSED*/
  315. void nop(w, e, vector, count)
  316.     Widget    w;
  317.     XEvent    *e;
  318.     String    *vector;
  319.     Cardinal    *count;
  320. {
  321.     ringbell();
  322. }
  323.  
  324. /*ARGSUSED*/
  325. void off(w, e, vector, count)
  326.     Widget    w;
  327.     XEvent    *e;
  328.     String    *vector;
  329.     Cardinal    *count;
  330. {
  331.     XCALC_PRE_OP(kOFF);
  332.     offf();
  333.     post_op();
  334. }
  335.    
  336. /*ARGSUSED*/
  337. void pi(w, e, vector, count)
  338.     Widget    w;
  339.     XEvent    *e;
  340.     String    *vector;
  341.     Cardinal    *count;
  342. {
  343.     XCALC_PRE_OP(kPI);
  344.     oneop(kPI);
  345.     post_op();
  346. }
  347.    
  348. /*ARGSUSED*/
  349. void power(w, e, vector, count)
  350.     Widget    w;
  351.     XEvent    *e;
  352.     String    *vector;
  353.     Cardinal    *count;
  354. {
  355.     XCALC_PRE_OP(kPOW);
  356.     rpn ? twof(kPOW) : twoop(kPOW);
  357.     post_op();
  358. }
  359.  
  360. /*ARGSUSED*/
  361. void quit(w, e, vector, count)
  362.     Widget    w;
  363.     XEvent    *e;
  364.     String    *vector;
  365.     Cardinal    *count;
  366. {
  367.     if (e->type == ClientMessage && e->xclient.data.l[0] != wm_delete_window)
  368.     ringbell();
  369.     else
  370.     Quit();
  371. }
  372.  
  373. /*ARGSUSED*/
  374. void recall(w, e, vector, count)
  375.     Widget    w;
  376.     XEvent    *e;
  377.     String    *vector;
  378.     Cardinal    *count;
  379. {
  380.     XCALC_PRE_OP(kRCL);
  381.     rpn ? memf(kRCL) : oneop(kRCL);
  382.     post_op();
  383. }
  384.     
  385. /*ARGSUSED*/
  386. void reciprocal(w, e, vector, count)
  387.     Widget    w;
  388.     XEvent    *e;
  389.     String    *vector;
  390.     Cardinal    *count;
  391. {
  392.     XCALC_PRE_OP(kRECIP);
  393.     oneop(kRECIP);
  394.     post_op();
  395. }
  396.    
  397. /*ARGSUSED*/
  398. void rightParen(w, e, vector, count)
  399.     Widget    w;
  400.     XEvent    *e;
  401.     String    *vector;
  402.     Cardinal    *count;
  403. {
  404.     XCALC_PRE_OP(kRPAR);
  405.     rparf();
  406.     post_op();
  407. }
  408.    
  409. /*ARGSUSED*/
  410. void roll(w, e, vector, count)
  411.     Widget    w;
  412.     XEvent    *e;
  413.     String    *vector;
  414.     Cardinal    *count;
  415. {
  416.     XCALC_PRE_OP(kROLL);
  417.     rollf();
  418.     post_op();
  419. }
  420.  
  421. /*ARGSUSED*/
  422. void scientific(w, e, vector, count)
  423.     Widget    w;
  424.     XEvent    *e;
  425.     String    *vector;
  426.     Cardinal    *count;
  427. {
  428.     XCALC_PRE_OP(kEE);
  429.     eef();
  430.     post_op();
  431. }
  432.  
  433. /*ARGSUSED*/
  434. void selection(w, e, vector, count)
  435.     Widget    w;
  436.     XEvent    *e;
  437.     String    *vector;
  438.     Cardinal    *count;
  439. {
  440.     do_select(((XButtonReleasedEvent *)e)->time);
  441. }
  442.  
  443. /*ARGSUSED*/
  444. void sine(w, e, vector, count)
  445.     Widget    w;
  446.     XEvent    *e;
  447.     String    *vector;
  448.     Cardinal    *count;
  449. {
  450.     XCALC_PRE_OP(kSIN);
  451.     oneop(kSIN);
  452.     post_op();
  453. }
  454.  
  455. /*ARGSUSED*/
  456. void square(w, e, vector, count)
  457.     Widget    w;
  458.     XEvent    *e;
  459.     String    *vector;
  460.     Cardinal    *count;
  461. {
  462.     XCALC_PRE_OP(kSQR);
  463.     oneop(kSQR);
  464.     post_op();
  465. }
  466.  
  467. /*ARGSUSED*/
  468. void squareRoot(w, e, vector, count)
  469.     Widget    w;
  470.     XEvent    *e;
  471.     String    *vector;
  472.     Cardinal    *count;
  473. {
  474.     XCALC_PRE_OP(kSQRT);
  475.     oneop(kSQRT);
  476.     post_op();
  477. }
  478.    
  479. /*ARGSUSED*/
  480. void store(w, e, vector, count)
  481.     Widget    w;
  482.     XEvent    *e;
  483.     String    *vector;
  484.     Cardinal    *count;
  485. {
  486.     XCALC_PRE_OP(kSTO);
  487.     rpn ? memf(kSTO) : oneop(kSTO);
  488.     post_op();
  489. }
  490.  
  491. /*ARGSUSED*/
  492. void subtract(w, e, vector, count)
  493.     Widget    w;
  494.     XEvent    *e;
  495.     String    *vector;
  496.     Cardinal    *count;
  497. {
  498.     XCALC_PRE_OP(kSUB);
  499.     rpn ? twof(kSUB) : twoop(kSUB);
  500.     post_op();
  501. }
  502.    
  503. /*ARGSUSED*/
  504. void sum(w, e, vector, count)
  505.     Widget    w;
  506.     XEvent    *e;
  507.     String    *vector;
  508.     Cardinal    *count;
  509. {
  510.     XCALC_PRE_OP(kSUM);
  511.     rpn ? memf(kSUM) : oneop(kSUM);
  512.     post_op();
  513. }
  514.    
  515. /*ARGSUSED*/
  516. void tangent(w, e, vector, count)
  517.     Widget    w;
  518.     XEvent    *e;
  519.     String    *vector;
  520.     Cardinal    *count;
  521. {
  522.     XCALC_PRE_OP(kTAN);
  523.     oneop(kTAN);
  524.     post_op();
  525. }
  526.    
  527. /*ARGSUSED*/
  528. void tenpower(w, e, vector, count)
  529.     Widget    w;
  530.     XEvent    *e;
  531.     String    *vector;
  532.     Cardinal    *count;
  533. {
  534.     XCALC_PRE_OP(k10X);
  535.     oneop(k10X);
  536.     post_op();
  537. }
  538.    
  539. /*ARGSUSED*/
  540. void XexchangeY(w, e, vector, count)
  541.     Widget    w;
  542.     XEvent    *e;
  543.     String    *vector;
  544.     Cardinal    *count;
  545. {
  546.     XCALC_PRE_OP(kXXY);
  547.     twof(kXXY);
  548.     post_op();
  549. }
  550.